/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ebasclient.gui.bank.item;

import ebasclient.abstracts.guielements.MyAbstractTableModel;
import java.util.List;
import org.coraci.bas.ws.Bank;

/**
 *
 * @author Luca
 */
public class BankTableModel extends MyAbstractTableModel<BankItem>{

    public BankTableModel(String[] labels, List<BankItem> datas) {
        super(labels, datas);
    }

    public BankTableModel() {
        super(new String[]{"Banche"}, null);
    }
    
    public Bank getSelectedBank(int rowIndex){
        return getData().get(rowIndex).getBank(); 
    }
    

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        return getData().get(rowIndex);
    }

    
    @Override
    public void refreshByObjectField(Object obj){
        if(obj instanceof Bank){
            for (int i = 0; i < getData().size(); i++) {
                System.out.println("valutando banca : "+((BankItem)getData().get(i)).getBank().getDenominazione());
                if(getData().get(i).getBank().getId() == ((Bank)obj).getId()){
                    System.out.println("equals!");
                    getData().get(i).setBank(((Bank)obj));
                    fireTableRowsUpdated(i,i);
                }
            }
        }
    }
    
}
